//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using ProjectBase.Core;

namespace Survey.Entity
{
    /// <summary>
    /// Entity Answer.
    /// </summary>
    [Serializable]
    public class Answer : Persistent<string>
    {
        public virtual string Title { get; set; }

        public virtual string Description { get; set; }

        public virtual int Count { get; protected set; }

        public virtual Question Question { get; set; }

        public virtual int Position { get; set; }

        public virtual float RatioInPercents
        {
            get { return Question.TotalAnswersCount == 0 ? 0 : Count / Question.TotalAnswersCount * 100; }
        }

        public virtual void IncreaseCount()
        {
            Count++;
        }

        #region virtual

        public virtual float Share
        {
            get
            {
                return Question.TotalAnswersCount > 0 ? (float)Count / Question.TotalAnswersCount : 0;
            }
        }

        public virtual float Percentage
        {
            get { return Share * 100; }
        }

        public virtual string ToCssPercentage()
        {
            return Percentage.ToString("N1", CultureInfo.InvariantCulture);
        }

        #endregion virtual

        #region override abstract

        /// <summary>
        /// Provides quick, string description about the 'Answer' instance
        /// </summary>
        public override string ToDisplay()
        {
            return Title;
        }

        /// <summary>
        /// Returned value should be handled as business unique key.
        /// Equal method (implemented in Tracked base class) will use it
        /// to compare two Answers
        /// </summary>
        protected override string GetDomainObjectSignature()
        {
            return IDToDisplay;
        }

        #endregion override abstract
    }
}